<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
(function(){
//****************************************************************************
// NEW API
module
extend
inherit

imports
exports
protects

//#module myModule.util.Date
//#from myModule.util.Date import X

this.module = function(options, fn){
	
    var type = typeof options, opt = {};
    
    function parseNS(ns){
        if (ns.indexOf("::") == -1)
        	opt.name = ns
       	else {
           	var n = ns.split("::");
           	opt.className = n[0];
           	opt.name = n[1];
       	}
    }
    
	if(!fn && type == "function")
		fn = options;

	if (type == "string") {
		parseNS(options);
		
	} else if (typeof options == "object" && (opt = options).ns) {
		parseNS(opt.ns);
	}

	return createModule(opt, fn);	
};

var extend = this.extend = function(l, r){
    //var api = reuseModule(l, r, true);
    //if (api) return api;

    var obj = l.prototype || l;
    for (var n in r)
        obj[n] = r[n];
        
    return obj;
};

//****************************************************************************
// Module

var modules = {};
var interfaces = ["init", "extend", "publish", "protect"];

function createModule(options, fn){

    var name = options.className;
    var Class = name && name != "Object" && getNS(name);

    var Module = function(){

    	// Initialize the module scope
    	var init, conf;
    	
        // Create the public scope
        var Scope = function(){};        
        if (Class) Scope.prototype = new Class;
        var scope = Scope.prototype;
        
        // Create the protected scope
        var _Scope = function(){};
        _Scope.prototype = new Scope;
        var _scope = _Scope.prototype;
        _scope.inherited = Class ? Class.prototype : null;

        // Extend the module API
        extend(_scope, {
            init:    function(f){ init = f; },
            publish: function(obj){ publish(_scope, scope, obj); },
            extend:  function(obj){ extend(scope, obj); },
            protect: function(obj){ extend(_scope, obj); }
        });

        // Register module
        var id = UID();
        var index = name || "Module_" + id;
        modules[index] = {
            id: id,
            name: name,
            scope: scope, 
            _scope: _scope
        };

        fn.apply(_scope);

        if(init)
            init.apply(_scope);

        return scope;
    };

    return Class ? Module : new Module;
};

function publish(_scope, scope, obj){
    var f;
    for (var n in obj)
    	scope[n] = typeof (f = obj[n]) == "function" ?  bind(f, _scope) : f;

    return scope;
};

function extendModule(options, fn){
	var ns = options.ns, obj = typeof ns == "string" ? NS(ns) : ns, 
		m = getModule(obj);

    if (!m) return undefined;

    var scope = m._scope;
    
    if (typeof obj == "function")
        obj.apply(scope);
    else
    	scope.extend(main);

    return m.scope;    
};

function getModule(scope){
    var m;
    for(var n in modules)
        if ((m = modules[n]).scope == scope)
            return m;

    return undefined;	
};

//****************************************************************************
// Util

function bind(f, _){return function(){return f.apply(_, arguments)}};

function UID(){return ++UID._};
UID._ = -1;

//****************************************************************************
// Namespaces

function NS(ns, source) {
    if (!ns) return false;

    var fn = {
        get: function(){
            return (o = target[ni])? (target = o) : undefined;      
        },
        set: function(){
            return (target = (o = target[ni]) ? o : target[ni] = {});
        }
    };
    
    var n = ns.split("."), target = window, o, f = fn[source?"set":"get"];
    for (var i = 0, l = n.length-1, ni; (ni = n[i]) && (i < l); i++)
        if(!f())
            return undefined;
    
    return source ? (target[ni] = source || {}) : target[ni];
};

//****************************************************************************


//****************************************************************************
}).apply(window);





//--------------------------------------------------------------------------
var mod = module("mod", function(){
//--------------------------------------------------------------------------

this.publish({
    show: function(){
        return "I can read " + this.inner() + " and " + hidden + " stuff.";
    }
});

var hidden = "hidden";

this.protect({
    inner: function(){
        return "protected";
    }
});

//--------------------------------------------------------------------------
});
//--------------------------------------------------------------------------
/**/





/*

//--------------------------------------------------------------------------
module("String::ns.MyString", function(){
//--------------------------------------------------------------------------

this.conf({   
});

this.init(function(){
	
});

this.extend({	
});

this.publish({
});

this.protect({
});

//--------------------------------------------------------------------------
});
//--------------------------------------------------------------------------


//--------------------------------------------------------------------------
module({ns: "String::ns.MyString", requires: "ns.util"}}, function(){
//--------------------------------------------------------------------------
    
this.extend({
});


this.protect({
});

//--------------------------------------------------------------------------
});
//--------------------------------------------------------------------------


/*
/**/


</script>
</head>
<body>
</body>
</html>